package com.whiteape.book.ui.adapter;

import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.BitmapCompat;
import androidx.core.graphics.drawable.DrawableCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.whiteape.book.R;
import com.whiteape.book.core.manager.MediaStorageManager;
import com.whiteape.book.model.dto.MediaChapterBean;
import com.whiteape.book.model.type.MediaType;
import com.whiteape.book.widget.ChapterButton;

import java.util.ArrayList;
import java.util.List;

public class ReadSettingColorAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

    private String selected;
    public ReadSettingColorAdapter(int layoutResId, @Nullable List<String> data) {
        super(layoutResId, data);
    }

    public void setSelected(String selected) {
        this.selected = selected;
    }

    public String getSelected() {
        return selected;
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        if(item.startsWith("#")) {
            helper.setImageDrawable(R.id.image_view, new ColorDrawable(Color.parseColor(item)));
        }else {
            helper.setImageBitmap(R.id.image_view, BitmapFactory.decodeFile(item));
        }
        helper.setVisible(R.id.read_bg_iv_checked, item.equals(selected));

    }
}
